home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT64.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  3.3 KB  |  112 lines

  1. /*
  2. ==============================================================================
  3.                       WordUp Graphics Toolkit Version 5.0                     
  4.                              Demonstration Program 64                         
  5.                                                                               
  6.  This is a picture viewer for PCX, IFF and LBM images. All images
  7.  are displayed using 320x200x256. Use the mouse to drag the image around
  8.  if it is larger than the screen. Press any key to exit the viewer.
  9.  
  10.  The image filename must be passed on the command line.
  11.  
  12.  *** PROJECT ***                                                             
  13.  This program needs the WGT5_WC.LIB file to be linked.   
  14.                                                                               
  15.  *** DATA FILES ***                                                          
  16.  Any PCX, IFF or LBM format pictures.                                   
  17.                                                            WATCOM C++ VERSION 
  18. ==============================================================================
  19. */
  20. #include <wgt5.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23.  
  24. color pal[256];
  25. block bigpic;
  26.  
  27. void main (int argc, char *argv[])
  28. {
  29.   short oldmode; 
  30.   short vx, vy, sx, sy, ox, oy;
  31.   short w, h;
  32.   char *pathbuf;
  33.   char drive[_MAX_DRIVE];
  34.   char dir[_MAX_DIR];
  35.   char fname[_MAX_FNAME];
  36.   char ext[_MAX_EXT];
  37.  
  38.   oldmode = wgetmode ();
  39.   if (argc < 2) 
  40.   {
  41.     printf ("WGT Example #64\n\n");
  42.     printf ("This program displays a picture and allows you to slide\n");
  43.     printf ("around with the mouse.\n");
  44.     printf ("\nUsage: WGT64 filename\n\n");
  45.     printf ("Where filename is a PCX, IFF or LBM image file format.\n");
  46.     exit (0);
  47.   }
  48.   vga256 ();
  49.   
  50.   vx = vy = 0;
  51.   
  52.   pathbuf = argv[1];
  53.   _splitpath (pathbuf, &drive, &dir, &fname, &ext);
  54.   
  55.   
  56.   /* Find out what kind of picture it is and load the image */
  57.   if (strcmp (ext, ".pcx") == 0)
  58.     bigpic = wloadpcx (argv[1], pal);
  59.   else if ((strcmp (ext, ".iff") == 0) || (strcmp (ext, ".lbm") == 0))
  60.     bigpic = wloadiff (argv[1], pal);
  61.   
  62.   if (bigpic != NULL)
  63.   {
  64.     wsetmode (3);
  65.     w = wgetblockwidth (bigpic);        /* Inform user of loaded data */
  66.     h = wgetblockheight (bigpic);
  67.     printf ("Image is %d by %d pixels.\n", w, h);
  68.     printf ("%d kbytes.\n\n\n", w*h);
  69.     getch ();
  70.     vga256 ();
  71.     wsetpalette (0, 255, pal);
  72.     wputblock (vx, vy, bigpic, NORMAL);
  73.     minit ();
  74.     mon ();
  75.     while (!kbhit ())                   /* Now let user scroll around */
  76.     {
  77.       if (mouse.but > 0)
  78.       {
  79.         sx = mouse.mx; 
  80.         sy = mouse.my;
  81.         ox = vx;
  82.         oy = vy;
  83.         moff ();
  84.         while (mouse.but > 0)
  85.         {
  86.           ox = vx - (sx - mouse.mx);
  87.           oy = vy - (sy - mouse.my);
  88.           if (ox + w < 320)
  89.             ox = 320 - w;
  90.           if (oy + h < 200)
  91.             oy = 200 - h;
  92.           if (ox > 0)
  93.             ox = 0;
  94.           if (oy > 0)
  95.             oy = 0;
  96.  
  97.           wputblock (ox, oy, bigpic, NORMAL);
  98.         }
  99.         vx = ox;
  100.         vy = oy;
  101.         mon ();
  102.       }
  103.     }
  104.     getch ();
  105.     wfreeblock (bigpic);
  106.     moff ();
  107.     mdeinit ();
  108.     wfade_out (0, 255, 20, pal);
  109.   }
  110.   wsetmode (oldmode);
  111. }
  112.